package com.houmeiyuan.huiguniang.service;

import com.houmeiyuan.huiguniang.modles.dao.UserDao;
import com.houmeiyuan.huiguniang.modles.domain.WxUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author wzn
 * @date 2019-07-20 16:23
 * @author lilanlan
 * @date 2019-08-07 20:27
 */

@Service
public class UserService {
    @Autowired
    public UserDao userDao;
    /**
     *
     * @param user
     * @return   判断注册微信用户
     */
     @Transactional
    public Integer registerByWX(WxUser user){
        if (userDao.selectByOpenId(user.getOpenId())!=null)
        {
            return 0;
        }
        return userDao.registerByWX(user);
    }
    /**
     *
     * @param openId
     * @return 判斷openid是否已存在
     */
    @Transactional
    public WxUser selectByOpenId(String openId){
        return userDao.selectByOpenId(openId);
    } //根据openid返回一个User实体类
    @Transactional
    public int updatePassword(Map<String,Object> map)
    {
         return userDao.updatePassword(map);
    }
    @Transactional
    public int updatePhone(Map<String,Object> map) { return userDao.updatePhone(map); }
    @Transactional
    public WxUser selectByphone(String phone)
    {
       return  userDao.selectByphone(phone);
    }

    /**
     * 查询不到则创建该openId的用户
     * @param mp
     * @return
     */
    @Transactional
    public Integer addWxUser(Map<String,Object>mp)
    {
        return userDao.addWxUser(mp);
    }
}
